/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.herenit.beijing.poc.base.action;

import com.herenit.beijing.poc.login.LoginForm;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.awt.ActionRegistration;
import org.openide.awt.ActionID;
import org.openide.windows.Mode;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;

@ActionID(category = "System",
id = "com.herenit.beijing.poc.base.LogOutAction")
@ActionRegistration(iconBase = "com/herenit/beijing/poc/base/1.png",
displayName = "com.herenit.beijing.poc.base.Bundle#CTL_LogOutAction")
public final class LogOutAction  implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {

        WindowManager wm = WindowManager.getDefault();

        for (Mode mode : wm.getModes()) {
            for (TopComponent tc : wm.getOpenedTopComponents(mode)) {
                tc.close();
            }
        }
        JButton ok = new JButton();
        ok.setText("登陆");        
        JButton cancel = new JButton();
        cancel.setText("重置");      
        cancel.addActionListener(new ActionListener() {  
            public void actionPerformed(ActionEvent arg0) {
               
            }
        });
        
        ok.addActionListener(new ActionListener() {
            
            public void actionPerformed(ActionEvent arg0) {
                //   simpleAuthenticate();
            }
        });
        LoginForm form=new LoginForm();
        NotifyDescriptor nd = new NotifyDescriptor.Confirmation(form, "登陆界面");
        nd.setOptions(new Object[]{ok, cancel});
        DialogDisplayer.getDefault().notifyLater(nd);
        
        nd.addPropertyChangeListener(new PropertyChangeListener() {
            
            public void propertyChange(PropertyChangeEvent evt) {
                if (NotifyDescriptor.CLOSED_OPTION.equals(evt.getNewValue())) {
                   //nd. exit();
                  
                }
            }
        });
    }
}
